/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.dspl.validate.violation;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.dspl.validate.ItemReference;

import java.util.List;

/**
 * Violation for a slice that references an inexistent table column.
 *
 * @author Maryla Ustarroz Calonge
 */
public final class SliceColumnNotFoundViolation extends Violation {

  private static final long serialVersionUID = -1857094927042943153L;

  private final String sliceId;
  private final String columnId;
  private final String tableId;

  public SliceColumnNotFoundViolation(
      ItemReference location,
      String sliceId,
      String columnId,
      String tableId) {
    super(Severity.ERROR, location);
    this.sliceId = sliceId;
    this.columnId = Preconditions.checkNotNull(columnId);
    this.tableId = Preconditions.checkNotNull(tableId);
  }

  @Override
  public String getDefaultTemplate() {
    return "Data slice %s refers to a column %s on table %s that does not exist";
  }

  @Override
  public List<Object> getDefaultTemplateParameters() {
    return ImmutableList.<Object>of(sliceId, columnId, tableId);
  }

  public String getSliceId() {
    return sliceId;
  }

  public String getColumnId() {
    return columnId;
  }

  public String getTableId() {
    return tableId;
  }

  @Override
  public <T> T accept(ViolationVisitor<T> visitor) {
    return visitor.visit(this);
  }
}
